<script lang="ts" setup>
import { getWebsitePageApi, type WebsiteVO } from '@/request/api/website'
import type { PageDTO, PageVO, ResultType } from '@/type/type'
import { useSystemStore } from '@/stores/system'

const systemStore = useSystemStore()
const url = systemStore.getRandomImg()

const page = reactive<PageDTO>({
  size: 30,
  current: 1,
  param: {}
})

let siteList = ref<WebsiteVO[]>([])
let isEmpty = ref<boolean>(false)
const getList = () => {
  page.param.isRecommend = false
  getWebsitePageApi(page).then((res: ResultType<PageVO<WebsiteVO>>) => {
    siteList.value = res.data.list
    isEmpty.value = res.data.isEmpty
  })
}

let recommendList = ref<WebsiteVO[]>([])
const getRecommendList = () => {
  page.param.isRecommend = true
  getWebsitePageApi(page).then((res: ResultType<PageVO<WebsiteVO>>) => {
    recommendList.value = res.data.list
  })
}

onMounted(() => {
  getList()
  getRecommendList()
})
</script>

<template>
  <el-container class="inner-box gap-5 pt-20" direction="vertical">
    <el-main>
      <el-container
        class="form-container use-shadow use-radius use-transitions-shadow-short items-center relative"
      >
        <ImageBox :lazy="false" :url="url" />
        <span class="absolute top-5 left-5 text-2xl flowing-text">有朋自远方来，不亦说乎！</span>
      </el-container>
    </el-main>
    <el-main class="my-10">
      <SiteForm />
    </el-main>
    <el-container class="w-full relative" direction="vertical">
      <WebsiteInfo />
    </el-container>
    <template v-if="recommendList.length">
      <el-container direction="vertical">
        <el-main class="!pb-0">
          <SvgIcon
            message="推荐"
            name="heat"
            parentClass="!text-xl w-fit pb-1.5 border-b-4"
            svg-class="!size-5"
          />
        </el-main>
        <el-main class="auto-column">
          <WebsiteBox :data="recommendList" />
        </el-main>
      </el-container>
    </template>
    <el-container direction="vertical">
      <el-main class="!pb-0">
        <SvgIcon
          message="友情链接"
          name="friend-link"
          parentClass="!text-xl w-fit pb-1.5 border-b-4"
          svg-class="!size-5"
        />
      </el-main>
      <el-main class="auto-column">
        <WebsiteBox :data="siteList" />
      </el-main>
      <template v-if="isEmpty">
        <el-empty class="z-20" description="没有更多内容了！" />
      </template>
    </el-container>
  </el-container>
</template>

<style lang="scss" scoped>
.form-container {
  height: 435px;
}
</style>
